"""""""""" SETTINGS
set nocompatible              " use VI incompatible features
"set gdefault                  " global search/replace by default
set number                    " show line numbers
set selectmode=mouse,key
set keymodel=startsel ",stopsel
set autoread                  " read outside modified files
set directory=c:\windows\temp " temp directory
set encoding=UTF-8
set formatoptions=tcrqn21
set guioptions=aAcrbie"m
set history=10000             " number of history items
set ignorecase                " ignore case when searching
set smartcase                " ignore case when searching
set hlsearch                  " highlight last search
set incsearch                 " show matches while searching
set laststatus=2              " always show status line
" set linebreak                 "
set scrolloff=2               " minlines to show around cursor
set sidescrolloff=4           " minchars to show around cursor
set shortmess=asTIA           " supress some file messages
set showbreak=>               " character to show that a line is wrapped
set showcmd                   " show number of selected chars/lines in status
set showmatch                 " briefly jump to matching brace
set matchtime=1               " show matching brace time (1/10 seconds)
set showmode                  " show mode in status when not in normal mode
" set nostartofline             " don't move to start of line after commands
set statusline=%-2(%M\ %)%5l,%-5v%<%F\ %m%=%(%-5([%R%H%W]\ %)\ %10([%Y]%{ShowFileFormatFlag(&fileformat)}\ %)\ %L\ lines%)
set undolevels=10000
set viminfo=%,h,'1000,"1000,:1000,n~/.viminfo
set virtualedit=block
set novisualbell
set whichwrap=<,>,h,l,b,s,~,[,]
set wildmenu
set wildmode=list:longest,full
set winaltkeys=no
set writebackup
set writeany
set iskeyword=@,48-57,128-167,224-235,_
"set isk=\\,/,\",\',\(,\),$,;,:,\,,.,<,>,-,\=
set showtabline=2
set mat=0

" windows and buffers
set noequalalways
set guiheadroom=0
set hidden
set splitbelow                " split windows below current one
set title


" always use LF line endings
"set ff=unix
"set ffs=unix

" tabs and indenting
set autoindent
set indentexpr=none
set noexpandtab
set tabstop=4
let &sw="\t"                  " wtf???


" syntax highlighting
syntax on
filetype plugin indent on

" look and feel
set guifont=Consolas:h14
source $VIMRUNTIME/mswin.vim
behave mswin
colorscheme desert

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""" commands
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
command! W :browse confirm saveas


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""" maps
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
source $VIM/vimfiles/_mine/functions.vim
source $VIM/vimfiles/_mine/snippetMagic.vim

call KeyMap('', '<F3>', ':e C:\\andrei\\work\\life.txt<CR>', '', 'niv')
call KeyMap('', '<F7>', ':RTlist<CR>', '', 'niv')
call KeyMap('', '<F8>', ':Tlist<CR>', 'silent', 'n')
call KeyMap('', '<S-Space>', ':call ExpandTemplate(1)<CR>', 'silent', 'i')
call KeyMap('M', 'q', ':q<CR>', '', 'ni')
call KeyMap('M', 'Q', ':q!<CR>', '', 'ni')
call KeyMap('M', 'w' , ':call ConditionalExecute("write")<CR>', 'silent', 'ni')
call KeyMap('M', 'W' , ':write!<CR>', 'silent', 'ni')
call KeyMap('M', '!', ':!!<CR>', 'silent', 'ni')
call KeyMap('M', '"', ':@:<CR>', 'silent', 'ni')
"call KeyMap('', '<F2>', ':let @/ = ""\|nohlsearch<CR>', 'silent', 'ni')
call KeyMap('', '<F9>', ':Tlist<CR>', 'silent', 'ni')
"call KeyMap('', '<F10>', ':call ConditionalExecute("write")\|next<CR>', 'silent', 'ni')
"call KeyMap('', '<F11>', ':qa!', '', 'ni')
call KeyMap('M', 'd', ':bd<CR>', 'silent', 'ni')
"call KeyMap('M', 'd', 'let g:gigi=bufnr('%')<CR>:call CycleBuffer(0)<CR>:exec ":bd"  . g:gigi . <CR>', 'silent', 'ni')
"call KeyMap('M', 'm', ':make\|copen<CR>', 'silent', 'ni')
"call KeyMap('M', '.', '<?php<CR>?><Left><Left><CR><Up><Tab>', 'silent', '_i')
call KeyMap('M', 'e', ':call OpenFileUnderCursor()<CR>', 'silent', 'ni')
call KeyMap('', '<Tab>', '>gv', 'silent', 'v')
call KeyMap('', '<S-Tab>', '<gv', 'silent', 'v')
"call KeyMap('', '<F1>', ':call ShowHelp()<CR>', 'silent', 'ni')
call KeyMap('M', "'", ':call ExpandTemplate()<CR>', 'silent', 'i')
"call KeyMap('M', 'Space', ':call ExpandTemplate()<CR>', 'silent', 'i')
"call KeyMap('C', 'Space', ':call ExpandTemplate()<CR>', 'silent', 'i')
call KeyMap('C', 'z', ':u<CR>', 'silent', 'i')
call KeyMap('M', 's', ':set scb<CR>', 'silent', 'ni')
call KeyMap('M', 'S', ':set noscb<CR>', 'silent', 'ni')
call KeyMap('M', 'u', 'guaw', 'silent', 'ni')
call KeyMap('M', 'U', 'gUaw', 'silent', 'ni')
call KeyMap('M', 'Space', ':simalt ~<CR>', 'silent', 'n')
"call KeyMap('', '<Down>', 'gj', 'silent', 'niv')
"call KeyMap('', '<Up>', 'gk', 'silent', 'niv')
call KeyMap('M', 'E', ':e .<CR>', 'silent', 'ni')
"call KeyMap('', ':', ':call ColonComplete()<CR>', 'silent', 'i')
call KeyMap('M', 'X', ':simalt ~x<CR>', 'silent', 'ni')
call KeyMap('M', 'Up', ':call SwapUp()<CR>', 'silent', 'ni')
call KeyMap('M', 'Down', ':call SwapDown()<CR>', 'silent', 'ni')
call KeyMap('M', 'a', ':let &wrap = !&wrap<CR>', 'silent', 'ni')
call KeyMap('M', 'X', ':simalt ~x<CR>', 'silent', 'nvi')
"call KeyMap('C', 'Space', '<C-w><C-w>', 'silent', 'n')
call KeyMap('C', 'Space', '<C-p>', 'silent', 'ni')
"call KeyMap('C', '<F2>', ':call SetMark()<CR>', 'silent', 'ni')
"call KeyMap('C', '1', ':buffer 11<CR>', 'silent', 'ni')
"call KeyMap('C', '2', ':buffer 12<CR>', 'silent', 'ni')
"call KeyMap('C', '3', ':buffer 13<CR>', 'silent', 'ni')
"call KeyMap('C', '4', ':buffer 14<CR>', 'silent', 'ni')
"call KeyMap('C', '5', ':buffer 15<CR>', 'silent', 'ni')
"call KeyMap('C', '6', ':buffer 16<CR>', 'silent', 'ni')
"call KeyMap('C', '7', ':buffer 17<CR>', 'silent', 'ni')
"call KeyMap('C', '8', ':buffer 18<CR>', 'silent', 'ni')
"call KeyMap('C', '9', ':buffer 19<CR>', 'silent', 'ni')
"call KeyMap('C', '0', ':buffer 20<CR>', 'silent', 'ni')
call KeyMap('M', 't', ':call InsertDateTime()<CR>', 'silent', 'i')
"call KeyMap('C', '_', ':<CR>', ':call Run_Snippet()', 'ni')
" this doesn't work with KeyMap for some strange reason
inoremap <C-space> <C-p>

" disable middle mouse button pasting
map  <MiddleMouse>  <Nop>
map  <2-MiddleMouse>  <Nop>
map  <3-MiddleMouse>  <Nop>
map  <4-MiddleMouse>  <Nop>
imap  <MiddleMouse>  <Nop>
imap  <2-MiddleMouse>  <Nop>
imap  <3-MiddleMouse>  <Nop>
imap  <4-MiddleMouse>  <Nop>

inoremap <S-CR> <C-o>O
inoremap <C-CR> <C-o>o
inoremap <C-S-CR> <CR><C-o>O
inoremap <silent> <Home> <C-o>:call HomeKey()<CR>
nnoremap <silent> <Home> :call HomeKey()<CR>

"noremap <C-Left>  ge
"noremap <C-Right> e
"noremap <C-S-Left>  ge
"noremap <C-S-Right> e

" make word back / forward to be cooloer
noremap W b
noremap b W

"""""""""""""" TabBar
let g:Tb_MaxSize = 0
let g:Tb_SplitBelow = 1
let g:Tb_MoreThanOne = 0
let g:Tb_MapCTabSwitchBufs = 1
let g:Tb_ModSelTarget = 1

source $VIM/vimfiles/_mine/tabbar.vim
source $VIM/vimfiles/plugin/matchit.vim

"""""""""""""" templates
"imap <C-_> <Esc>:call ExpandTemplate()<CR>a
"map  <C-_>      :call ExpandTemplate()<CR>a
"source $VIM/vimfiles/plugin/expand_template2.vim

"""""""""""""" taglist settings
let Tlist_Ctags_Cmd = "C:/andrei/programs/bin/ctags.exe"
let Tlist_Compact_Format = 1
let Tlist_File_Fold_Auto_Close = 1
let Tlist_Use_Right_Window = 1
let Tlist_Exit_OnlyWindow = 1
let Tlist_WinWidth = 40 

"""""""""""""" textmate snippets
"imap <Tab> <Plug>Jumper 
"""""""" php
"Iabbr pcls class @classname@ {<CR><Tab>function @classname@() {<CR>}<CR>}end
"Iabbr forin for @element@ in @collection@<CR>@element@.@@<CR>end
"Iabbr forin for @element@ in @collection@<CR>@element@.@@<CR>end

"""""""""""""" autocmds
au bufenter * call ContextSettings()
function! ContextSettings()
	set indentexpr=none
	let l:NBuffers = bufnr('$')
	if l:NBuffers > 1 && bufexists(1) && buflisted(1) && !getbufvar(1, "&bufsecret")
		:bw 1
	endif
endfunction
"au BufRead * silent! %s/\r//ge " remove all ^M from file
au GUIEnter * simalt ~x " maximize on startup

au Filetype ruby let b:foldsearchprefix='\v^\s*(#.*)?$'
autocmd BufRead *.mxml set filetype=xml
au! FileType xml,sgml,entity,xslt,svg,xhtml,xsl,xsd
	\ if !exists("b:match_words") |
	\ let b:match_ignorecase=0 | let b:match_words =
	\ '<:>,' .
	\ '<\@<=!--:-->,'.
	\ '<\@<=?\k\+:?>,'.
	\ '<\@<=\([^ \t>/]\+\)\%(\s\+[^>]*\%([^/]>\|$\)\|>\|$\):<\@<=/\1>,'.
	\ '<\@<=\%([^ \t>/]\+\)\%(\s\+[^/>]*\|$\):/>'
	\ | endif
au BufNewFile,BufRead *.html let g:snip_start_tag = "@"
au BufNewFile,BufRead *.html let g:snip_end_tag = "@"

"""""""""""""" wiki integration
let g:wiki_path = "c:/andrei/programs/wiki/to_put"

let javaScript_fold=1
